# -*- coding: utf-8 -*-
#
# Author:: hanjunfeng
# Date:: 2022/7/6
import os.path


from submodules.common.lib.json_ import dict_to_json_file, json_file_to_dict
from submodules.common.lib.local_paths import project_tmp_path
from lib.ts_ import (
    get_stock_list,
    get_market_info_all_tx,
    get_market_info_all_tx_sorted,
)


def main():
    file_path = os.path.join(project_tmp_path, "top_stock_list.json")
    top_stock_list = []
    stock_list = get_stock_list()
    market_info_all_tx = get_market_info_all_tx(stock_list)

    market_info_all_tx_sorted = get_market_info_all_tx_sorted(market_info_all_tx)

    count = 0
    for item in market_info_all_tx_sorted:
        market_value = float(item[1][44])
        if 1000 > market_value > 50:
            count += 1
            top_stock_list.append(item)
    dict_to_json_file(top_stock_list, file_path)


if __name__ == "__main__":
    # main()

    file_path = os.path.join(project_tmp_path, "top_stock_list.json")
    d = json_file_to_dict(file_path)
    tx_code_list = [x[0] for x in d]
    for item in tx_code_list:
        print(item)
